package com.hb.common.util;

public class Result<T> {

    private int code;
    private boolean success;
    private String message;
    private T data;

    // 默认构造函数
    public Result() {}

    // 带参数的构造函数
    public Result(int code, boolean success, String message, T data) {
        this.code = code;
        this.success = success;
        this.message = message;
        this.data = data;
    }

    // Getters and Setters
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 静态方法用于快速创建Result对象
    public static <T> Result<T> success(T data) {
        return new Result<>(0, true, "Success", data);
    }

    // 静态方法用于快速创建Result对象
    public static <T> Result<T> success() {
        return new Result<>(0, true, "Success", null);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(0, true, message, data);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(500, false, message, null);
    }

    public static <T> Result<T> fail(int code, String message) {
        return new Result<>(code, false, message, null);
    }

    public static <T> Result<T> fail(int code, String message, T data) {
        return new Result<>(code, false, message, data);
    }
}